package com.henry.config;

import com.henry.enums.ExchangeName;
import com.henry.enums.QueueNames;
import com.henry.enums.RoutingKeyName;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 订阅模型config
 */
@Configuration
public class DirectConfig {

    @Bean
    public DirectExchange defaultExchange() {
        return new DirectExchange(ExchangeName.DEFAULT.name());
    }

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(ExchangeName.DIRECT_EXCHANGE.name());
    }

    @Bean
    public Queue directMsgQueue() {
        return new Queue(QueueNames.DIRECT_MSG_QUEUE.name(), true);
    }

    @Bean
    public Binding directBinding() {
        return BindingBuilder
                .bind(directMsgQueue())
                .to(directExchange())
                .with(RoutingKeyName.DIRECT_MSG_ROUTING_KEY.name());
    }

}